public class Demo2 {
    public static void main(String[] args) {
        Object locker=new Object();
        Thread t1=new Thread(()->{
            synchronized (locker){
                System.out.println("t1在wait之前");
                try {
                    System.out.println("t1执行到wait，释放锁");
                    locker.wait();
                    System.out.println("t1被唤醒");
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        });
        Thread t2=new Thread(()->{
            synchronized (locker){
                System.out.println("t2获取到锁,释放锁");
                try {
                    locker.wait();
                    System.out.println("t2被唤醒");
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        });
        Thread t3=new Thread(()->{
            synchronized (locker){
                System.out.println("t3唤醒t1");
                locker.notifyAll();
                System.out.println("同步代码块执行完，t3释放锁");
            }
        });
        t1.start();
        t2.start();
        t3.start();
    }
}
